package com.it.doudizhu1;

import java.util.ArrayList;
import java.util.Collections;

public class PokerGame {
    //准备牌
    //静态代码块
    //特点，随着类的加载而加载，只执行一次
    //1.创建一个集合存入准备牌
    static ArrayList<String> Poker = new ArrayList<String>();
    static{
        String[] color = {"♦","♣","♥","♠"};
        String[] number = {"3","4","5","6","7","8","9","10","J","Q","K","A","2"};

        //牌盒
        for(String c : color){
            for(String n : number){
                Poker.add(c+n);
            }
        }
        Poker.add("小王");
        Poker.add("大王");
        //System.out.print(list);
    }
    public PokerGame() {
        //洗牌
        Collections.shuffle(Poker);
        System.out.println(Poker);

        //发牌
        //定义四个集合，底牌，地主牌，平民牌
        ArrayList<String> lord = new ArrayList<>();
        ArrayList<String> player1 = new ArrayList<>();
        ArrayList<String> player2 = new ArrayList<>();
        ArrayList<String> player3 = new ArrayList<>();

        //遍历集合，得到每一个元素
        for(int i = 0; i < Poker.size(); i++){
            String poker = Poker.get(i);
            if(i<=2){
                lord.add(poker);
                continue;
            }

            if(i%3 == 0){
                player1.add(poker);
            }else if(i%3 == 1){
                player2.add(poker);
            }else{
                player3.add(poker);
            }
        }
        lookPoker("小王",player1);
        lookPoker("小周",player2);
        lookPoker("小肖",player3);

        //看牌
    }

    //遍历集合的方法
    public void lookPoker(String name,ArrayList<String> list){
        System.out.print(name+":");
        for(String poker : list){
            System.out.print(poker+"");
        }
        System.out.println();
    }
}
